package com.mdd.car.controller.vehicle;


import com.mdd.car.params.vehicle.VehicleCreateValidate;
import com.mdd.car.params.vehicle.VehicleSearchValidate;
import com.mdd.car.params.vehicle.VehicleUpdateStatusValidate;
import com.mdd.car.params.vehicle.VehicleUpdateValidate;
import com.mdd.car.service.IVehicleService;
import com.mdd.car.vo.vehicle.VehicleDetailVo;
import com.mdd.car.vo.vehicle.VehicleVo;
import com.mdd.common.aop.CurrentUser;
import com.mdd.common.aop.Log;
import com.mdd.common.aop.NotPower;
import com.mdd.common.base.page.PageValidate;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validate.IdValidate;
import com.mdd.common.validator.annotation.IDMust;
import com.mdd.system.entity.SystemAuthAdmin;
import com.mdd.system.vo.SystemAuthAdminInformVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@RestController
@RequestMapping("api/vehicle")
@Api(tags = "车辆管理")
public class VehicleController {

    @Resource
    IVehicleService iVehicleService;

    @NotPower
    @GetMapping("/list")
    @ApiOperation(value="车辆列表")
    public AjaxResult<PageResult<VehicleVo>> list(@Validated PageValidate pageValidate,
                                                  @Validated VehicleSearchValidate searchValidate, @CurrentUser SystemAuthAdminInformVo systemAuthAdmin) {
        PageResult<VehicleVo> list = iVehicleService.list(pageValidate, searchValidate,systemAuthAdmin);
        return AjaxResult.success(list);
    }

    @NotPower
    @GetMapping("/unBindList")
    @ApiOperation(value="待绑定车辆列表")
    public AjaxResult<PageResult<VehicleVo>> unBindList(@Validated PageValidate pageValidate,
                                                  @Validated VehicleSearchValidate searchValidate, @CurrentUser SystemAuthAdminInformVo systemAuthAdmin) {
        PageResult<VehicleVo> list = iVehicleService.unBindList(pageValidate, searchValidate,systemAuthAdmin);
        return AjaxResult.success(list);
    }
    @NotPower
    @GetMapping("/detail")
    @ApiOperation(value="车辆详情")
    public AjaxResult<VehicleDetailVo> detail(@Validated @IDMust() @RequestParam("id") Long id) {
        VehicleDetailVo detail = iVehicleService.detail(id);
        return AjaxResult.success(detail);
    }
    @NotPower
    @Log(title = "车辆新增")
    @PostMapping("/add")
    @ApiOperation(value="车辆新增")
    public AjaxResult<Object> add(@Validated @RequestBody VehicleCreateValidate createValidate) {
        iVehicleService.add(createValidate);
        return AjaxResult.success();
    }
    @NotPower
    @Log(title = "车辆编辑")
    @PostMapping("/edit")
    @ApiOperation(value="车辆编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody VehicleUpdateValidate updateValidate) {
        iVehicleService.edit(updateValidate);
        return AjaxResult.success();
    }
    @NotPower
    @Log(title = "更新车辆状态")
    @PostMapping("/updateStatus")
    @ApiOperation(value="更新车辆状态")
    public AjaxResult<Object> updateStatus(@Validated @RequestBody VehicleUpdateStatusValidate vehicleUpdateStatusValidate) {
        iVehicleService.updateStatus(vehicleUpdateStatusValidate);
        return AjaxResult.success();
    }
    @NotPower
    @Log(title = "车辆删除")
    @PostMapping("/del")
    @ApiOperation(value="车辆删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iVehicleService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
